{extend name="Public:content"}
{block name="button"}
<!--工具栏 start-->
<div class="row">
    <div class="col-sm-12 m-b-xs">
        <button class="btn btn-white btn-sm" type="button"  onClick="$.Oa.reload()"><i class="fa fa-refresh"></i> 刷新</button>
        <a class="btn btn-primary btn-sm"  title="添加分类" onclick="category_index.add()" ><i class="fa fa-plus"></i> 添加分类</a>
    </div>
</div>
<!--工具栏 end-->
{/block}
{block name="content"}
<div class="table-responsive" style="overflow-x:initial">
    <table id="category_table" ></table>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    window.category_index = {
        //定义工具栏
        //toolbar: "#category_index_toolbar",
        add: function(){ //添加
            parent.layer.open({
                type: 2,
                title: '{$title} > 添加',
                shadeClose: false,
                shade: 0.8,
                maxmin: false, //开启最大化最小化按钮
                area: ['960px', '650px'],
                content: '{:url("$classuri/add")}?iframe='+window.name,
                yes: function (index, layero){},
                end: function (){}
            });
        },
        del: function(_this,id){
            if(!id){
                layer.msg('请选择需要删除的数据');
                return false;
            }
            $.Oa.delete(_this,function(data){
                //删除该行
                $("#category_table").bootstrapTable('remove',{field:'id',values:[id]});
            })
        },
        //操作格式化
        opert: function(value,row){
            var rst = '';
            var del_auth = '{:auth("$classuri/del")}';
            if(del_auth) {
                rst +=  '<a onClick="category_index.del(this,'+row.id+')" data-href="{:url(\"$classuri/del\")}" data-id="'+row.id+'" class="btn btn-outline btn-xs btn-danger" title="删除" >删除</a>';
            }
            return rst;
        }
    }
    $('#category_table').bootstrapTable({
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        url:"{:url(\"$classuri/index\")}",
        detailView: true, //父子类
        pageNumber: 1, //初始化加载第一页，默认第一页
        showRefresh: false,
        pagination:true,//是否分页
        sidePagination:'server',//指定服务器端分页
        queryParamsType : "",
        queryParams: function(params){
            return {limit:params.pageSize,page:params.pageNumber,order:params.sortOrder};
        },//参数
        pageSize:10,//单页记录数
        pageList:[10,20,30,40],//分页步进值
        // responseHandler:responseHandler,//请求数据成功后，渲染表格前的方法
        columns :[
            {field:'id',title:'ID',width: 20},
            {field:'sort',title:'排序',width: 20,formatter:function(value,row){return '<a id="sort" data-pk="'+row.id+'" data-id="'+row.id+'">'+value+'</a>'}},
            {field:'cate',title:'菜单名称',width: 150,formatter:function(value,row){return '<a id="cate" data-pk="'+row.id+'" data-id="'+row.id+'">'+value+'</a>'}},
//            {field:'action',title:'操作',width: 100,formatter:category_index.opert},
        ],
        onExpandRow:function(index, row, $detail){
            InitSubTable(index, row, $detail);
        },
        onLoadSuccess: function(data){
            $.each(['#sort','#cate'],function(i,ob){
                $("#category_table "+ob).editable({
                    url: function (params){$.Oa.updateField('{:url("$classuri/edit")}',params.pk,params.name,params.value)},
                    type: 'text'
                });
            })
        }
    })
    var InitSubTable = function (index, row, $detail) {
        var cur_table = $detail.html('<table></table>').find('table');
        $(cur_table).bootstrapTable({
            method: 'post',
            contentType: "application/x-www-form-urlencoded",
            url:"{:url(\"$classuri/soncate\")}",
            detailView: true, //父子类
            showRefresh: false,
            pagination:false,//是否分页
            sidePagination:'server',//指定服务器端分页
            queryParams: {pid:row.id},//参数
            columns :[
                {field:'id',title:'ID',width: 20},
                {field:'sort',title:'排序',width: 20,formatter:function(value,row){return '<a id="sort" data-pk="'+row.id+'" data-id="'+row.id+'">'+value+'</a>'}},
                {field:'cate',title:'菜单名称',width: 150,formatter:function(value,row){return '<a id="cate" data-pk="'+row.id+'" data-id="'+row.id+'">'+value+'</a>'}},
                {field:'action',title:'操作',width: 100,formatter:category_index.opert},
            ],
//            onExpandRow:function(index, row, $detail){
//                InitSubTable(index, row, $detail);
//            },
            onLoadSuccess: function(data){
                $.each(['#sort','#cate'],function(i,ob){
                    $(cur_table).find(ob).editable({
                        url: function (params){$.Oa.updateField('{:url("$classuri/edit")}',params.pk,params.name,params.value)},
                        type: 'text'
                    });
                })
                //隐藏+号
                $(cur_table).find('tr').each(function(){
                    $(this).find('td').eq(0).html('');
                })
            }
        })
    }
</script>
{/block}s